package com.scada.controller;


import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.scada.contant.MessageConstants;
import com.scada.model.bean.Permission;
import com.scada.model.result.PageInfo;
import com.scada.model.result.ResponseBean;
import com.scada.service.PermissionService;


/**
 * @author 黄胜
 * 16-10-26 10:26
 * 系统权限管理方法
 *
 */
@Controller
@RequestMapping("Permssion")
public class PermissionController extends BaseController{
	
	@Autowired
	private PermissionService perService;

	@RequestMapping(value = "toPermission")
	public ModelAndView toMain(){
		
		return new ModelAndView("system/permission");
	}
	
	@RequestMapping(value = "listData")
	@ResponseBody
	public String listData(HttpServletRequest request,@ModelAttribute PageInfo<Permission> pageInfo,
			@ModelAttribute Permission permission){
		pageInfo.setPageSize(Integer.parseInt(request.getParameter("length")));
		permission.setState(MessageConstants.State.STATE_DEL.getKey());
		pageInfo.setCondition(permission);
		pageInfo = perService.selectByPrimaryKey(pageInfo);
		return toJson(pageInfo);
	}
	
	@RequestMapping(value = "insertSelective")
	public ModelAndView insertSelective(Permission permission){
		ResponseBean rb = new ResponseBean();
		
		rb = perService.insertSelective(permission);
		
		return rb.getJsonModelView();
	}
	
	@RequestMapping(value = "deleteByPrimaryKey")
	public ModelAndView deleteByPrimaryKey(String ids){
		
		ResponseBean rb = new ResponseBean();
		
		rb = perService.deleteByPrimaryKey(ids);
		
		return rb.getJsonModelView();
	}
	
	@RequestMapping(value = "updateByPrimaryKeySelective")
	public ModelAndView updateByPrimaryKeySelective(@ModelAttribute Permission permission){
		
		ResponseBean result = perService.updateByPrimaryKeySelective(permission);
		
		return result.getJsonModelView();
	}
	
	@RequestMapping(value = "validateIndex")
	public String validateIndex(@ModelAttribute Permission permission){
		
		Boolean result = perService.validateIndex(permission);
		if(result){
			return "true";
		}else{
			return "false";
		}
	}
	
	@RequestMapping(value = "selectById")
	@ResponseBody
	public Permission selectById(int Id){
		
		return perService.selectById(Id);
	}
}
